package models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import play.db.jpa.Model;

/**
 * @author amr abbas
 * 
 */
@Entity
public class planComment extends Model{

	public double rating;
	@Lob
	public String content;
	public Date time;
	@ManyToOne
	public Plan plan;
	@ManyToOne
	public User creator;
	@OneToOne
	public ActionLog generatedLog;
	@OneToMany
	public List<Notification> generatedNotifications;

	/**
	 * 
	 * @param rating
	 *            the rating of this comment (likeness vs hating)
	 * @param content
	 *            the content of the comment
	 * @param time
	 *            the time at which the comment was written
	 * @param creator
	 *            the user who created wrote the comment
	 * @param idea
	 *            the idea under which the comment was written
	 * @param generatedLog
	 *            the action log associated with this comment
	 */

	public planComment(double rating, String content, User creator,
			Plan plan, ActionLog generatedLog) {
		this.rating = rating;
		this.content = content;
		this.time = new Date();
		this.creator = creator;
		this.plan = plan;
		this.generatedLog = generatedLog;
		this.generatedNotifications = new ArrayList<Notification>();
		this.save();
	}
	
	/**
	 * @author Ahmed Mahmoud
	 * @return
	 */
	public boolean cascadeDelete(){
		plan.planComments.remove(this);
		plan.save();
		this.delete();
		return true;
	}

}
